package cn.achao.csr.base.exception;

import cn.achao.csr.base.constant.Constants;
import lombok.Getter;

/**
 * 自定义异常类
 *
 */
@Getter
public class BusinessException extends RuntimeException {

    /**
     * 异常码
     */
    private final int code;

    /**
     * 系统来源
     */
    private final String sysSource;

    /**
     * 描述
     */
    private final String description;

    public BusinessException(String message, int code, String description, String sysSource) {
        super(message);
        this.code = code;
        this.sysSource = sysSource;
        this.description = description;
    }

    /**
     * 简单失败，并记录日志
     * @param message
     * @param sysSource
     * @return
     */
    public static BusinessException fail(String message, String sysSource) {
        return fail(message, sysSource, true);
    }

    /**
     * 简单失败，并记录日志
     * @param message
     * @param sysSource
     * @return
     */
    public static BusinessException fail(String message, String sysSource, boolean logFlag) {
        // TODO 记录日志
        if (logFlag) {
            //SpringUtils.getBean("");
        }
        return new BusinessException(message, Constants.FAIL, message, sysSource);
    }

}
